<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务，帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件，不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
declare (strict_types = 1);

namespace app\common\model\ding;

use cores\BaseModel;

/**
 * 文章模型
 * Class Article
 * @package app\common\model
 */
class Food extends BaseModel
{
    // 定义表名
    protected $name = 'ding_food';

    // 定义主键
    protected $pk = 'food_id';

    public function category()
    {
        $module = self::getCalledModule();
        return $this->hasOne("app\\{$module}\\model\\ding\\foods\\Category", 'category_id', 'category_id')
        ;
    }
    public function addImport($data)
    {

        $data['shop_id']     = $shopId;
        $data['create_time'] = time();
        $data['store_id']    = self::$storeId;
        $this->save($data);

        return true;
    }
    public function image()
    {
        $module = self::getCalledModule();
        return $this->hasOne("app\\{$module}\\model\\UploadFile", 'file_id', 'image_id')
        ;
    }
    public function image2()
    {
        $module = self::getCalledModule();
        return $this->hasOne("app\\{$module}\\model\\UploadFile", 'file_id', 'image_id')->bind(['image_url' => 'preview_url'])
        ;
    }
    /**
     * 文章详情
     * @param int $articleId
     * @param array $with
     * @return array|null|static
     */
    public static function detail(int $articleId, array $with = [])
    {
        return self::get($articleId, $with);
    }
}
